install_none_gui_software(){
  sudo apt-get update && sudo apt-get upgrade -y
  sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
  sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
  sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
  sudo apt-get install -y git openssh-server software-properties-common apt-transport-https
  sudo apt-get install -y zsh bash csh tcsh ksh fish tmux tilix
  sudo apt-get install -y vim neovim emacs nano gedit
  sudo apt-get install -y nodejs npm
  sudo apt-get install -y wget curl axel aria2
}

# install docker
install_docker(){
  # if [ -n `which docker`]; then
  if type docker >/dev/null 2>&1; then
    echo 'docker command exist'
  else
    echo 'docker does not exist'
    sudo rm -f /etc/apt/sources.list.d/docker.list
    sudo apt-get remove docker docker-engine docker.io containerd runc

    sudo apt-get update
    sudo apt-get -y install \
      ca-certificates \
      curl \
      gnupg \
      lsb-release
      
    sudo mkdir -p /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
      $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo chmod a+r /etc/apt/keyrings/docker.gpg
    sudo apt-get update
    sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-compose
    sudo gpasswd -a ${USER} docker
    sudo systemctl restart docker
    sudo systemctl enable docker
    sudo systemctl status docker
  fi
  
}

# login setting: https://docs.docker.com/desktop/get-started/#credentials-management-for-linux-users
install_docker_desktop(){
  sudo apt-get update
  sudo apt-get install -y pass qemu
  wget https://desktop.docker.com/linux/main/amd64/docker-desktop-4.12.0-amd64.deb
  sudo dpkg -i docker-desktop-4.12.0-amd64.deb
  rm -f docker-desktop-4.12.0-amd64.deb
}

# install podman
install_podman(){
  # if [ -n `which podman`]; then
  if type podman >/dev/null 2>&1; then
    echo 'code command exist'
  else
    echo 'podman does not exist'
    sudo apt update 
    sudo apt-get install -y podman
  fi
}

# -------------------install gui software-----------------------------
install_flatapk(){
  # if [ -n `which flatapk`]; then
  if type flatpak >/dev/null 2>&1; then
    echo 'flatpak command exist'
  else
    echo 'flatapk does not exist'
    sudo apt-get update
    sudo apt-get -y install flatpak
    flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
  fi
 }
install_vscode(){
  # if [ -n `which code`]; then
  if type code >/dev/null 2>&1; then
    echo 'code command exist'
  else
    echo 'code command does not exist'
    sudo apt-get update && sudo apt-get upgrade -y
    wget -O- https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor | sudo tee /usr/share/keyrings/vscode.gpg
    echo deb [arch=amd64 signed-by=/usr/share/keyrings/vscode.gpg] https://packages.microsoft.com/repos/vscode stable main | sudo tee /etc/apt/sources.list.d/vscode.list
    sudo apt-get update
    sudo apt-get install code -y
  fi
}
install_utools(){
  rm -f ./utools_3.0.3_amd64.deb
  wget https://res.u-tools.cn/version2/utools_3.0.3_amd64.deb
  sudo dpkg -i ./utools_3.0.3_amd64.deb
  rm -f ./utools_3.0.3_amd64.deb
}
install_flatpak_software(){
  # https://flathub.org/home
  flatpak install flathub net.cozic.joplin_desktop
  flatpak install flathub md.obsidian.Obsidian
  flatpak install flathub com.logseq.Logseq
  flatpak install flathub org.wezfurlong.wezterm
  flatpak install flathub com.google.Chrome
  flatpak install flathub org.chromium.Chromium
  flatpak install flathub org.mozilla.firefox
  flatpak install flathub com.microsoft.Edge
  flatpak install flathub net.werwolv.ImHex
  flatpak install flathub com.axosoft.GitKraken
  flatpak install flathub com.visualstudio.code
  flatpak install flathub com.sublimetext.three
  flatpak install flathub com.jetbrains.PyCharm-Community
  flatpak install flathub com.jetbrains.IntelliJ-IDEA-Community
  flatpak install flathub io.dbeaver.DBeaverCommunity
  flatpak install flathub com.github.marktext.marktext
  flatpak install flathub io.typora.Typora
}
install_gui_software(){
  sudo apt-get update
  sudo apt-get install -y tilix gnome-tweaks
  install_flatapk
  install_vscode
  # install_utools # BUG: ERROR 403: Forbidden.
}

# -------------------software settings------------------------
# 1. git settings

git_settings(){
  sudo apt-get update
  sudo apt install -y git openssh-server
  rm -rf ~/.ssh
  rm -rf ~/git_settings
  git clone https://gitee.com/lgf1244/git_settings.git ~/git_settings
  chmod 600 ~/git_settings/.ssh/*_id_rsa
  chmod 600 ~/git_settings/.ssh/config
  cp -rp ~/git_settings/.ssh ~
  rm -rf rp ~/git_settings
  ssh -T git@gitee.com
}




# install_none_gui_software
install_gui_software
# install_docker
# install_docker_desktop
# install_podman

# git_settings





















